import request from "../request";
import {FetchPhoneNumRes, LoginRes, ResponseRET, UserPermissionRes} from "../../types/responseTypes";
import {BindLoginParams, FetchPhoneParams, RegisterParams} from "../../types/requestTypes";
/**
 * 微信登录
 * 使用接口（“微信登录”）获取TOKEN和当前操作员资料（需保存）。
 * 如果返回数据‘error’为‘user_error’时，说明系统中没有此用户需进行用户登录关联系统用户或用户注册。
 */
export const wxLogin = async (): Promise<LoginRes> => {
    // @ts-ignore
    const {code} = await uni.login({
        provider: 'weixin'
    })
    return request.post('/STUA_wxlogin', {
        js_code: code
    },false, true)
}

/**
 * 获取微信手机号码
 * @param params
 */
export const fetchPhoneNum = (params: FetchPhoneParams): Promise<FetchPhoneNumRes> => request.post('/STUA_wxphoneno',params, false, true)

/**
 * 用户登录关联系统用户
 * @param params
 */
export const bindLogin = (params: BindLoginParams): Promise<ResponseRET> => request.post('/restapi/STUA_mbreport_new/DL_CUSERS',params,true)

/**
 * 注册
 * @param params
 */
export const register = (params: RegisterParams): Promise<ResponseRET> => request.post('/restapi/STUA_mbreport_new/ZC_CUSERS',params,true)

/**
 * 查看用户权限
 * @param userId
 */
export const getPermission = (userId: string | number): Promise<UserPermissionRes> => request.post('/restapi/STUA_mbreport_new/RD_USER_QX',{
    OPERATOR_ID: userId
},true)
